package eecs.util;

//Class: EECS 285
//Project: 4 (Virtual Markerboard)
//Due Date: Monday December 6th, 2010


/**
 * A custom exception class. Constructing this exception causes the following to
 * be displayed on System.err:
 * 
 * <pre>
 * 1) Class, Method, & Line Number where the exception was thrown.
 * 2) The error message passed in.
 * </pre>
 * @author Vidal Borromeo
 */
@SuppressWarnings("serial")
public class MException extends RuntimeException
{
  /**
   * 
   * Constructor.
   * 
   * @param msg
   *          The message to be displayed to the error console.
   * @author Vidal Borromeo
   */
  public MException(String msg)
  {
    super(msg);

    if( eecs285.proj4.gui.Markerboard.DEBUG_MODE )
    {
      synchronized( System.err )
      {
        StackTraceElement ste = getStackTrace()[0];
        String source_class = ste.getClassName();
        source_class = source_class
            .substring(source_class.lastIndexOf(".") + 1);
        System.err.println(source_class + "." + ste.getMethodName()
            + "() Line " + ste.getLineNumber() + ": " + msg);
      }// sync
    }// if
  }// ctor

}// MException
